<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>挂失信息列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f6f8;
            padding: 20px;
        }
        h1 {
            text-align: center;
            color: #333;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            background-color: white;
        }
        th, td {
            padding: 12px;
            border: 1px solid #ddd;
            text-align: center;
        }
        th {
            background-color: #f2f2f2;
        }
        tr:nth-child(even) {
            background-color: #fafafa;
        }
    </style>
</head>
<body>

<h1>挂失信息列表</h1>

<table id="loseTable">
    <thead>
    <tr>
        <th>用户名</th>
        <th>卡号</th>
        <th>挂失原因</th>
        <th>挂失时间</th>
        <th>身份证号</th>
        <th>手机号</th>
        <th>家庭住址</th>
    </tr>
    </thead>
    <tbody>
    <!-- 数据通过 JavaScript 动态插入 -->
    </tbody>
</table>

<script>    fetch('/admin/api/loses')
    .then(response => {
        if (!response.ok) {
            throw new Error("网络响应失败");
        }
        return response.json();
    })
    .then(data => {
        const tbody = document.querySelector("#loseTable tbody");
        data.forEach(lose => {
            const row = document.createElement("tr");
            row.innerHTML = `
                    <td>${lose.user}</td>
                    <td>${lose.card}</td>
                    <td>${lose.reason}</td>
                    <td>${lose.time}</td>
                    <td>${lose.idnumber}</td>
                    <td>${lose.phone}</td>
                    <td>${lose.home}</td>
                `;
            tbody.appendChild(row);
        });
    })
    .catch(error => {
        console.error('获取数据失败:', error);
        alert('无法加载挂失信息，请检查网络或后端服务');
    });
</script>
<a href="AdminHome.html">退出</a>

</body>
</html>